home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / httpproxy / deinstall.rexx < prev    next >
OS/2 REXX Batch file  |  1996-08-20  |  2KB  |  78 lines

  1. /* Remove new installation inside files. Returns 0 on success, 20 on failure. */
  2. /* Usage: rx deinstall.rexx CheckText/A Files/M */
  3.  
  4. /*
  5.  * A copy of every 'file' is made into 'file.rexxbackup'.
  6.  *
  7.  * All lines between ";BEGIN 'CheckText'" and ";END 'CheckText'" or
  8.  * /-*BEGIN 'CheckText'*-/ and /-*END 'CheckText'*-/ (of course without the '-'s)
  9.  * are removed.
  10.  *
  11.  * When the files cannot be opened, they are skipped.
  12.  * When a write fails or the ending statement is missing, the backup file
  13.  * is restored and the script returns 20.
  14.  */
  15.  
  16. parse arg CheckText AllArgs
  17. address command
  18.  
  19. do forever
  20.    parse VAR AllArgs File AllArgs
  21.    if File == "" then
  22.       leave
  23.    if ~exists(File) then                /* skip not existing files */
  24.       iterate
  25.    "delete >nil: "File".rexxbackup"
  26.    "rename "File File".rexxbackup"
  27.    if (open("r",File".rexxbackup","READ") ~= 1) then
  28.    do
  29.       say "Reading file "File" failed..."
  30.       "rename "File".rexxbackup "File   /* and rename back... */
  31.       exit 20
  32.    end
  33.    if (open("w",File,"WRITE") ~= 1) then
  34.    do
  35.       say "Writing to file "File" failed..."
  36.       "rename "File".rexxbackup "File   /* and rename back... */
  37.       exit 20
  38.    end
  39.    do while (eof("r") = 0)
  40.       line = readln("r")
  41.       if (line == "" & eof("r") = 1) then
  42.      leave
  43.       if (~ (BeginExp(line))) then
  44.      call writeln("w",line)
  45.       else
  46.       do while (~ (EndExp(line)))
  47.      if eof("r") then
  48.      do
  49.         say "begin expression not ending with end expression"
  50.         call close("r")
  51.         call close("w")
  52.         "delete >nil: "File
  53.         "rename "File".rexxbackup "File    /* and rename back... */
  54.         exit 20
  55.      end
  56.      line = readln("r")
  57.       end
  58.    end
  59.    call close("r")
  60.    call close("w")
  61.  
  62. end
  63.  
  64. exit 0
  65.  
  66. BeginExp: procedure expose CheckText
  67.    parse Arg n
  68.    if (n == ";BEGIN "CheckText) | (n == "/*BEGIN "CheckText"*/") then
  69.       return 1
  70.    return 0
  71.  
  72. EndExp: procedure expose CheckText
  73.    parse Arg n
  74.    if (n == ";END "CheckText) | (n == "/*END "CheckText"*/") then
  75.       return 1
  76.    return 0
  77.  
  78.